﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Models;

namespace DAL
{
    /// <summary>
    /// 购物车
    /// </summary>
   public class CartDAL
    {
        //购物车添加
        public static int cartAdd(Cart c) {
            string sql = "insert into tb_Cart(UserID,FoodID,number,Total) values(@UserID,@FoodID,@number,@Total)";
            SqlParameter[] para = {
            new SqlParameter("@UserID",c.UserID),
            new SqlParameter("@FoodID",c.FoodID),
            new SqlParameter("@number",c.Number),
            new SqlParameter("@Total",c.Total),
            };
            return SqlDBHelper.ExecuteNonQuery(sql, para);
        }
        //购物车查询
        public static DataTable cartCK(int id) {
            string sql = "select * from tb_Cart c,tb_Food f where c.FoodID=f.FoodID and c.UserID="+id;
            return SqlDBHelper.GetDataTable(sql);
        }
        //购物车总价
        public static object totalDAL(int id)
        {
            string sql = "select sum(Total) from tb_Cart where UserID="+id;
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //购物车中的商品
        public static object jjsp(int id) {
            string sql = "select count(*) from tb_Cart where UserID=" + id;
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //根据id删除购物车中的商品
        public static int delID(int id) {
            string sql = "delete from tb_Cart where CartID=" + id;
            return SqlDBHelper.ExecuteNonQuery(sql);
        }
        //美食id
        public static object meiID(int id)
        {
            string sql = "select FoodID from tb_Cart where UserID=" + id;
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //删除购物车里的内容
        public static int deleteAll(int id) {
            string sql = "delete from tb_Cart where UserID="+id;
            return SqlDBHelper.ExecuteNonQuery(sql);
        }
        //购物车里面美食的数量
        public static object numID(int id)
        {
            string sql = "select number from tb_Cart where UserID=" + id;
            return SqlDBHelper.ExecuteScalar(sql);
        }
    }
}
